package Json;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
* @author jie
* @version 创建时间：2018年6月13日 下午11:26:26
* 格式化时间
*/
public class FormatTest {
	public static void main(String[] args) {
		Gson gson2 = new GsonBuilder()
				.create();
		
		Gson gson = new GsonBuilder().setPrettyPrinting()// 格式化输出
				.setDateFormat("yyyy-MM-dd HH:mm:ss:SSS")// 格式化时间
				.create();
		Date date = new Date();
		Strategies2 strategies = new Strategies2(date, new Date(date.getTime() + 1000000));
		System.out.println();
		System.out.println(gson.toJson(strategies));
		System.err.println(gson2.toJson(strategies));

		String json = "{\n" + "  \"date\": \"2018-03-17 19:38:50:033\",\n"
				+ "  \"date2\": \"2018-03-17 19:55:30:033\"\n" + "}";
		System.out.println();
		System.out.println(gson.fromJson(json, Strategies2.class));
		System.err.println(gson2.fromJson(json, Strategies2.class));
	}
}

class Strategies2 {

	private Date date;

	private Date date2;

	public Strategies2(Date date, Date date2) {
		this.date = date;
		this.date2 = date2;
	}

//	@Override
//	public String toString() {
//		return "Strategies2 [date=" + date + ", date2=" + date2 + "]";
//	}

	@Override
	public String toString() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS", Locale.CHINA);
		return "Strategies{" + "date=" + simpleDateFormat.format(date) + ", date2=" + simpleDateFormat.format(date2)
				+ '}';
	}
	
	

}